package com.ruoyi.job.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.core.domain.business.waterManagement.WrStatvolD;
import com.ruoyi.common.core.domain.business.waterManagement.WrStatvolH;
import com.ruoyi.common.core.domain.business.waterManagement.WrStatvolM;
import com.ruoyi.common.core.utils.DateUtils;
import com.ruoyi.job.mapper.WrStatvolHMapper;
import com.ruoyi.job.mapper.WrStatvolMMapper;
import com.ruoyi.job.service.IWrStatvolHService;
import com.ruoyi.job.service.IWrStatvolMService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * 测站月水量数据Service业务层处理
 * 
 * @author hwd
 * @date 2023-02-20
 */
@Service
public class WrStatvolMServiceImpl extends ServiceImpl<WrStatvolMMapper, WrStatvolM> implements IWrStatvolMService
{
    @Autowired
    private WrStatvolMMapper wrStatvolMMapper;

    /**
     * 查询测站月水量数据
     * 
     * @param statCd 测站月水量数据主键
     * @return 测站月水量数据
     */
    @Override
    public WrStatvolM selectWrStatvolMByStatCd(String statCd)
    {
        return wrStatvolMMapper.selectWrStatvolMByStatCd(statCd);
    }

    /**
     * 查询测站月水量数据列表
     * 
     * @param wrStatvolM 测站月水量数据
     * @return 测站月水量数据
     */
    @Override
    public List<WrStatvolM> selectWrStatvolMList(WrStatvolM wrStatvolM)
    {
        return wrStatvolMMapper.selectWrStatvolMList(wrStatvolM);
    }

    /**
     * 新增测站月水量数据
     * 
     * @param wrStatvolM 测站月水量数据
     * @return 结果
     */
    @Override
    public int insertWrStatvolM(WrStatvolM wrStatvolM)
    {
        return wrStatvolMMapper.insertWrStatvolM(wrStatvolM);
    }

    /**
     * 修改测站月水量数据
     * 
     * @param wrStatvolM 测站月水量数据
     * @return 结果
     */
    @Override
    public int updateWrStatvolM(WrStatvolM wrStatvolM)
    {
        return wrStatvolMMapper.updateWrStatvolM(wrStatvolM);
    }

    /**
     * 批量删除测站月水量数据
     * 
     * @param statCds 需要删除的测站月水量数据主键
     * @return 结果
     */
    @Override
    public int deleteWrStatvolMByStatCds(String[] statCds)
    {
        return wrStatvolMMapper.deleteWrStatvolMByStatCds(statCds);
    }

    /**
     * 删除测站月水量数据信息
     * 
     * @param statCd 测站月水量数据主键
     * @return 结果
     */
    @Override
    public int deleteWrStatvolMByStatCd(String statCd)
    {
        return wrStatvolMMapper.deleteWrStatvolMByStatCd(statCd);
    }

    @Override
    public WrStatvolM countYearByWrStatvolM(String statCd, Date year) {
        String [] strings= DateUtils.jsYmd(year);
        String yy =strings[0];
        return wrStatvolMMapper.countYearByWrStatvolM(statCd,yy);
    }

    @Override
    public void insertOrUpdateWrStatvolM(WrStatvolD wrStatvolD) {
        WrStatvolM saveWrStatvolM =new WrStatvolM();
        saveWrStatvolM.setStatCd(wrStatvolD.getStatCd());
        saveWrStatvolM.setMonLevel(wrStatvolD.getDayLevel());
        saveWrStatvolM.setMonFlow(wrStatvolD.getDayFlow());
        saveWrStatvolM.setMonVol(wrStatvolD.getDayVol());
        String [] strings= DateUtils.jsYmd(wrStatvolD.getStatDay());
        String yy =strings[0];
        String mm =strings[1];
        if (mm.length()==1){
            mm=0+mm;
        }
        saveWrStatvolM.setStatMon(yy+mm);
        wrStatvolMMapper.insertOrUpdateWrStatvolM(saveWrStatvolM);
    }

    @Override
    public WrStatvolM countWiOrgVolMByWrStatvolM(String statCd, Date day) {
        String [] strings= DateUtils.jsYmd(day);
        String yy =strings[0];
        String mm =strings[1];
        if (mm.length()==1){
            mm=0+mm;
        }
        return wrStatvolMMapper.countWiOrgVolMByWrStatvolM(statCd,yy+mm);
    }

    public static void main(String[] args) {
        String [] strings= DateUtils.jsYmd(new Date());
        String yy =strings[0];
        String mm =strings[1];
        if (mm.length()==1){
            mm=0+mm;
        }
        System.out.println(yy+mm);
    }


}
